﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using COMOSOFT.Class;
using COMOSOFT.Main;
using COMOSOFT.JobManagement;
using DevExpress.XtraGrid.Views.BandedGrid;
using MSoft.Shipping.Control;

namespace COMOSOFT.JobManagement.Froms
{
    public partial class FrmJobGeneral : Form
    {
        ClassShare cls = new ClassShare("FrmJobGeneral");
        
        FrmMain main = null;
        public FrmJobGeneral(FrmMain _main)
        {
            InitializeComponent();
            main = _main;
        }

        #region [Form Load]
        private void FrmJobGeneral_Load(object sender, EventArgs e)
        {
            try
            {
                // TODO: This line of code loads data into the 'dataSetOrderManagement.Employee' table. You can move, or remove it, as needed.
                this.employeeTableAdapter.Fill(this.dataSetOrderManagement.Employee);
                gridControl_JobGeneral.DataSource = dataSet_JobManagement.sp_JobGeneral;
                sp_JobGeneralTableAdapter.Fill(dataSet_JobManagement.sp_JobGeneral, DateTime.Now.ToString("yyyy"), ClassShare.Usid.ToString());
               
                DataTable dtb = dataSet_JobManagement.sp_JobGeneral;
                for (int i = 0; i < dtb.Columns.Count; i++)
                {
                    int outP;
                    if (Int32.TryParse(dtb.Columns[i].ToString(), out outP))
                    {
                        BandedGridView view = gridControl_JobGeneral.MainView as BandedGridView;
                        BandedGridColumn colLevel = view.Columns.AddVisible(dtb.Columns[i].ColumnName) as BandedGridColumn;
                        colLevel.Caption = "Level " + dtb.Columns[i].ColumnName;
                        this.gridBand2.Columns.Add(colLevel);
                    }

                }               

                colYear.GroupIndex = 0;
                colMonth.GroupIndex = 1;              
                colCraeteDate.GroupIndex = 2;
                colStatus.GroupIndex = 3;   
             
                colCraeteDate.SortOrder = DevExpress.Data.ColumnSortOrder.Descending;
                colCraeteDate.DisplayFormat.FormatType = DevExpress.Utils.FormatType.DateTime;
                colCraeteDate.DisplayFormat.FormatString = "{0:dd-MM-yyyy}";             

                //bandedGridView_JobGaneral.ExpandAllGroups();
                bandedGridView_JobGaneral.BestFitColumns();
                new BandedCellSelectionHelper(bandedGridView_JobGaneral);                
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        #endregion

        #region [View Details]
        private void bandedGridView_JobGaneral_DoubleClick(object sender, EventArgs e)
        {
            try
            {
                if (bandedGridView_JobGaneral.FocusedRowHandle >= 0)
                {
                    int JID = Convert.ToInt32(bandedGridView_JobGaneral.GetFocusedDataRow()["JID"]);
                    JobManagement.Froms.FrmJobManagement frJobM = new FrmJobManagement(JID);
                    frJobM.MdiParent = main;
                    frJobM.Show();
                    frJobM.LoadData();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        #endregion

        private void refreshToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FrmJobGeneral_Load(sender, e);
        }
    }
}
